<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        section {
            width: 300px;
            height: 400px;
            outline: 5px dashed red;
            margin: 20px;
            float: left;
            padding: 8px;
            box-sizing: border-box;
        }

        .box {
            width: 100%;
            height: 100px;
            background-color: #e9e9e9;
            margin-bottom: 8px;
        }

    </style>
</head>
<body>
    <section>
        <div class="box" draggable="true">1</div>
        <div class="box" draggable="true">2</div>
    </section>
    <section></section>

    <script>

        let currentBox = null;

        const boxList = document.querySelectorAll('.box');

        for (const box of boxList) {
            // 拖拽开始 记录当前正在拖拽的元素
            box.addEventListener('dragstart', function () {
                currentBox = box;
            });
        }
        // 拖拽的元素
        // dragstart*: 拖拽开始
        // drag*: 拖拽中
        // dragend*: 拖拽结束

        // 目标元素
        // dragenter: 拖拽进入
        // dragleave: 拖拽离开
        // dragover*: 拖拽悬停(没有e.preventDefault() drop事件就会失效)
        // drop*: 放置

        const dropareaList = document.querySelectorAll('section');

        for (const droparea of dropareaList) {
            droparea.addEventListener('dragover', e => e.preventDefault());
            droparea.addEventListener('drop', function (e) {
                console.log(e);
                // 使用我按下的那个box
                droparea.appendChild(currentBox);
            });
        }

    </script>
</body>
</html>